﻿using SCG.TurboSprite;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SCG.SolarVengeance
{
    public class JumpGateSprite : Sprite
    {
        //constructor
        public JumpGateSprite()
            : base()
        {
            int radius = Constants.CellHalf - 8;
            PointF pt1 = new PointF(-radius, -radius);
            PointF pt2 = new PointF(radius, -radius);
            PointF pt3 = new PointF(radius, radius);
            PointF pt4 = new PointF(-radius, radius);
            _ps1 = new PolygonSprite(pt1, pt2, pt3, pt4);
            RandomizePolygon(_ps1);   
            _ps2 = new PolygonSprite(pt1, pt2, pt3, pt4);
            RandomizePolygon(_ps2);
            _ps2.Spin = _ps1.Spin == SpinType.Clockwise ? SpinType.CounterClockwise : SpinType.Clockwise;
            Shape = new RectangleF(-radius, -radius, radius, radius);
        }

        //process
        public override void Process()
        {
            _ps1.Surface = Surface;
            _ps1.Position = Position;
            _ps1.PreProcess();
            _ps1.Process();
            _ps2.Surface = Surface;
            _ps2.Position = Position;
            _ps2.PreProcess();
            _ps2.Process();
        }

        //render
        public override void Render(Graphics g)
        {
            _ps1.Render(g);
            _ps2.Render(g);
        }

        //private members
        private PolygonSprite _ps1;
        private PolygonSprite _ps2;

        //randomize each one
        private void RandomizePolygon(PolygonSprite ps)
        {
            ps.Position = Position;
            ps.Spin = Sprite.RND.NextDouble() > 0.5 ? SpinType.Clockwise : SpinType.CounterClockwise;
            ps.SpinSpeed = Sprite.RND.Next(20) + 1;
            ps.IsFilled = true;
            ps.FillColor = Sprite.ColorFromRange(Color.Black, Color.White);
            ps.Color = ps.FillColor;
        }
    }
}
